home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / AEnormalConstraintTemplate.m < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.7 KB  |  251 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //
  20. //  Creation Date:    June 3, 1997
  21. //  Author:        sw
  22. //
  23. //  Procedure Name:
  24. //    AEnormalConstraintTemplate
  25. //
  26. //  Description Name;
  27. //    Creates the attribute editor controls for the normalConstraint Node
  28. //
  29. //  Input Value:
  30. //    nodeName 
  31. //
  32. //  Output Value:
  33. //    None
  34. // 
  35.  
  36. global string $gAEnormalConstraintWorldUpWidgets[];    // hold info plus widgets
  37.  
  38. global proc AEenableRestNormalCallback( string $nodeName )
  39. {
  40.     int $enable = `getAttr ($nodeName+".enableRestPosition")`;
  41.     editorTemplate -dimControl $nodeName "restRotate" (! $enable);    
  42. }
  43.  
  44.  
  45. global proc AEnormalConstraintTemplate ( string $nodeName )
  46. {
  47.     editorTemplate -beginScrollLayout;
  48.         
  49.         // include/call base class/node attributes
  50.         AEtransformMain $nodeName;
  51.     
  52.         editorTemplate -beginLayout "Normal Constraint Attributes" -collapse 0;
  53.             editorTemplate -addControl "aimVector";
  54.             editorTemplate -addControl "upVector";
  55.             editorTemplate -addControl "worldUpType" 
  56.                     "AEnormalConstraintWorldUpControls";
  57.             editorTemplate -addControl "worldUpVector"; 
  58.             editorTemplate -callCustom
  59.                 "AEnormalConstraintWorldUpObjectNew"
  60.                 "AEnormalConstraintWorldUpObjectReplace"
  61.                 "worldUpMatrix";
  62.  
  63.             editorTemplate -addSeparator;
  64.  
  65.             editorTemplate -addControl "constraintRotate";
  66.             editorTemplate -addControl "constraintVector";
  67.             editorTemplate -addControl "enableRestPosition" "AEenableRestNormalCallback";            
  68.             editorTemplate -addControl "restRotate";            
  69.  
  70.         editorTemplate -endLayout;
  71.     
  72.         // include/call base class/node attributes
  73.         AEtransformNoScroll $nodeName;
  74.  
  75.         // supressed attributes
  76.         editorTemplate -suppress "constraintRotateOrder";
  77.         editorTemplate -suppress "constraintTranslate";
  78.         editorTemplate -suppress "constraintRotatePivot";
  79.         editorTemplate -suppress "constraintJointOrient";
  80.         editorTemplate -suppress "constraintParentInverseMatrix";
  81.         editorTemplate -suppress "worldUpType";
  82. //        editorTemplate -suppress "worldUpVector";
  83.         editorTemplate -suppress "worldUpMatrix";
  84.         editorTemplate -suppress "target";
  85.         editorTemplate -suppress "constraintRotateTranslate";
  86.  
  87.     editorTemplate -addExtraControls;
  88.     editorTemplate -endScrollLayout;
  89. }
  90.  
  91. proc setStateOfWorldUpObjectControls( string $nodeName, int $state )
  92. {
  93.     global string $gAEnormalConstraintWorldUpWidgets[];
  94.  
  95.     // Update the world up object text field for all attribute
  96.     // editors looking at this node
  97.  
  98.     int $i;
  99.     for ($i = 0; $i < size($gAEnormalConstraintWorldUpWidgets); $i += 3 )
  100.     {
  101.         if ( $nodeName == $gAEnormalConstraintWorldUpWidgets[$i] ) 
  102.         {
  103.             string $worldUpObjectControl = $gAEnormalConstraintWorldUpWidgets[$i+2];
  104.             if ( `textFieldGrp -exists $worldUpObjectControl` )
  105.             {
  106.                 textFieldGrp -e -enable $state $worldUpObjectControl;
  107.             }
  108.         }
  109.     }
  110. }
  111.  
  112. // This proc will dim/undim the world up controls as required
  113. global proc AEnormalConstraintWorldUpControls(string $nodeName)
  114. {
  115.     $nodeAttr = $nodeName +".worldUpType";
  116.     int $value = `getAttr $nodeAttr`;
  117.     switch ($value) 
  118.     {
  119.     case 0: // Scene Up
  120.     case 4: // None
  121.         editorTemplate -dimControl $nodeName "worldUpVector" true;
  122.         setStateOfWorldUpObjectControls( $nodeName, false );
  123.         break;
  124.     case 1: // Object Up
  125.         editorTemplate -dimControl $nodeName "worldUpVector" true;
  126.         setStateOfWorldUpObjectControls( $nodeName, true );
  127.         break;
  128.     case 2: // Object Rotation Up
  129.         editorTemplate -dimControl $nodeName "worldUpVector" false;
  130.         setStateOfWorldUpObjectControls( $nodeName, true );
  131.         break;
  132.     case 3: // Vector
  133.         editorTemplate -dimControl $nodeName "worldUpVector" false;
  134.         setStateOfWorldUpObjectControls( $nodeName, false );
  135.         break;
  136.     default:
  137.         break;
  138.     }
  139. }
  140.  
  141.  
  142. // This proc gets called by the UI widget for the
  143. // worldUpMatrix attribute
  144. //
  145. global proc AEnormalConstraintWorldUpObjectControlProc(string $nodeName,
  146.                                                     string $widget)
  147. {
  148.     // Get the current value of the widget
  149.  
  150.     string $value = `textFieldGrp -q -text $widget`;
  151.  
  152.     // setAttr just isn't sufficient for worldUpMatrix
  153.  
  154.     normalConstraint -edit -worldUpObject $value $nodeName;
  155. }
  156.  
  157. // This proc gets called by the scriptJob which is watching the
  158. // worldUpMatrix attribute
  159. //
  160. global proc AEnormalConstraintWorldUpObjectScriptJobProc(string $nodeName,
  161.                                                       string $widget)
  162. {
  163.     textFieldGrp -e
  164.         -text `normalConstraint -q -worldUpObject $nodeName`
  165.         $widget;
  166. }
  167.  
  168. // Local proc shared by AEnormalConstraintWorldUpObjectNew() and AEnormalConstraintWorldUpObjectReplace()
  169. proc updateWorldUpObject( string $nodeName, string $plug, string $worldUpObjectControl )
  170. {
  171.     // Initialize/update the textFieldGrp
  172.  
  173.     string $cmd1 = "AEnormalConstraintWorldUpObjectControlProc "+$nodeName+" "+$worldUpObjectControl;
  174.     textFieldGrp -e
  175.         -text `normalConstraint -q -worldUpObject $nodeName`
  176.         -cc $cmd1
  177.         $worldUpObjectControl;
  178.     
  179.     // Setup/update the scriptJob callback mechanism
  180.  
  181.     string $cmd2 = "AEnormalConstraintWorldUpObjectScriptJobProc "+$nodeName+" "+$worldUpObjectControl;
  182.     scriptJob -rp -p $worldUpObjectControl -ac $plug $cmd2;
  183. }
  184.  
  185. // The custom creation proc for the worldUpMatrix attribute
  186. //
  187. global proc AEnormalConstraintWorldUpObjectNew( string $plug )
  188. {
  189.     global string $gAEnormalConstraintWorldUpWidgets[];
  190.  
  191.     // Get the node name
  192.  
  193.     string $buffer[];
  194.     tokenize($plug,".|",$buffer);
  195.     string $nodeName = $buffer[0];
  196.  
  197.     // Save the node name and the parent info in the global
  198.     // string array
  199.  
  200.     int $numNormalConstraintAEs = size($gAEnormalConstraintWorldUpWidgets);
  201.     $gAEnormalConstraintWorldUpWidgets[$numNormalConstraintAEs] = $nodeName;
  202.     $gAEnormalConstraintWorldUpWidgets[$numNormalConstraintAEs+1] = `setParent -q`;
  203.  
  204.     // Create the textFieldGrp
  205.  
  206.     setUITemplate -pst attributeEditorTemplate;
  207.  
  208.     string $worldUpObjectControl =
  209.         `textFieldGrp -l "World Up Object" AEnormalConstraintWorldUpObjectField`;
  210.  
  211.     // Save the control for possible later reuse
  212.     $gAEnormalConstraintWorldUpWidgets[$numNormalConstraintAEs+2] = $worldUpObjectControl;
  213.  
  214.     setUITemplate -ppt;
  215.  
  216.     updateWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  217. }
  218.  
  219. global proc AEnormalConstraintWorldUpObjectReplace( string $plug )
  220. {
  221.     global string $gAEnormalConstraintWorldUpWidgets[];
  222.  
  223.     // Get the node name
  224.  
  225.     string $buffer[];
  226.     tokenize($plug,".|",$buffer);
  227.     string $nodeName = $buffer[0];
  228.  
  229.     // Reuse the existing control
  230.  
  231.     string $curParent = `setParent -q`;
  232.     int $index = -1;
  233.     int $i;
  234.     for ( $i = 0; $i < size($gAEnormalConstraintWorldUpWidgets); $i += 3 ) 
  235.     {
  236.         if ( $curParent == $gAEnormalConstraintWorldUpWidgets[$i+1] )
  237.         {
  238.             $index = $i;
  239.             break;
  240.         }
  241.     }
  242.     string $worldUpObjectControl = "AEnormalConstraintWorldUpObjectField";
  243.     if ($index != -1)
  244.     {
  245.         $gAEnormalConstraintWorldUpWidgets[$index] = $nodeName;
  246.         $worldUpObjectControl = $gAEnormalConstraintWorldUpWidgets[$index+2];
  247.     }
  248.  
  249.     updateWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  250. }
  251.